package com.kt.kvw.generator;

import com.kt.kvw.exception.IDGeneratorException;

import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2020-07-08
 * Time: 21:19
 */
public final class IDGenerator {

    /**
     * UUID
     *
     * @return
     */
    public static String uuid() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static String uuid(String name){
        return UUID.fromString(name).toString();
    }

    public static String uuid(byte[] name) {
        if (name == null || name.length == 0) {
            throw new IDGeneratorException("生成ID的信息不能为空");
        }
        return UUID.nameUUIDFromBytes(name).toString();
    }
}
